package com.huawei.hoto;
import lombok.extern.slf4j.Slf4j;

import java.util.Random;
import java.util.Scanner;
@Slf4j//lombom工具插件，（logback引用
public class Game {
    public static void main(String[] args){
        int win=0;//胜利的局数
        int lose=0;//失败的局数
        int draw=0;//打平的局数
        int r =0;//想游玩的局数

        log.info("石头剪刀布游戏已启动！");
        log.info("请输入你想玩的局数：");
        Scanner round = new Scanner(System.in);//手动输入局数
        r = round.nextInt();//把手动输入的数值赋给r
        for(int i=1;i<=r; i++) {
            log.info("第" + i + "局：");
            log.info("键位提示：1:'出石头'，2：'出剪刀'，3:‘出布’");
            log.info("选择你要出的手势:");
            Scanner sc = new Scanner(System.in);
            String enter = sc.next();
            int randomNumber = new Random().nextInt(3) + 1;//随机数范围选择3（0~2）再+1取（1~2）
            if (enter.equals("2")) {
                if (randomNumber == 1) {
                    log.info("电脑出的是剪刀");
                    log.info("该局为平局");
                    draw++;
                } else if (randomNumber == 2) {
                    log.info("电脑出的是布");
                    log.info("您赢了");
                    win++;
                } else if (randomNumber == 3) {
                    log.info("电脑出的是石头");
                    log.info("你输了");
                    lose++;
                }
            } else if (enter.equals("1")) {
                if (randomNumber == 1) {
                    log.info("电脑出的是剪刀");
                    log.info("您赢了");
                    win++;
                } else if (randomNumber == 2) {
                    log.info("电脑出的是布");
                    log.info("您输了");
                    lose++;
                } else if (randomNumber == 3) {
                    log.info("电脑出的石头");
                    log.info("该局为平局");
                    draw++;
                }
            } else if (enter.equals("3")) {
                if (randomNumber == 1) {
                    log.info("电脑出的是剪刀");
                    log.info("您输了");
                    lose++;
                } else if (randomNumber == 2) {
                    log.info("电脑出的是布");
                    log.info("该局为平局");
                    draw++;
                } else if (randomNumber == 3) {
                    log.info("电脑出的石头");
                    log.info("你赢了");
                    win++;
                }
            } else {
                log.info("输入错误！请输入’剪刀‘或’石头‘或’布‘");
                i--;
            }
        }
        log.info("***********");
        log.info("!GAME OVER！");
        log.info("***********");
        log.info("统计目前为止您共赢了"+win+"局,输了"+lose+"局，平了"+draw+"局");
        int computer=5- draw - win;
        if (computer == win){
            log.info("你和电脑打成平手");
        }else if (computer < win){
            log.info("你打败了电脑");
        }else if (computer > win){
            log.info("你输给了电脑");
        }
    }
}
